<template>
	<el-container>
		<el-main class='x-main-edit'>
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-tabs type="border-card" v-model="page_tag">
					<!---->
					<!---->
					<el-tab-pane :label="page_info.title" name="1">
						<el-form-item label="车牌号" prop="sku_id">
							<el-select filterable v-model="form.sku_id" placeholder="请选择">
								<el-option v-for="item in page_info.list_sku"
										   :label="item.csku_car_no"
										   :key="item.csku_id"
										   :value="item.csku_id">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="违章时间" prop="celog_date">
							<el-date-picker
								style="width: 200px;"
								v-model="form.celog_date"
								type="datetime"
								placeholder="选择违章时间"
								:picker-options="g_cc.picker_options"
								default-time="00:00:00"
								value-format="yyyy-MM-dd HH:mm:ss">
							</el-date-picker>
						</el-form-item>
						<el-form-item label="订单号" prop="celog_order_id">
							<el-input v-model="form.celog_order_id" class="x-input-60" placeholder="订单号"></el-input>
							<el-button type="primary" @click="funcSearchOrder" size="mini">搜索行程订单</el-button>
							<div class="x-alert">
								<span>搜索行程订单：需要选择车牌号及违章时间</span>
							</div>
							<div v-if="user_phone!=''">
								<div>姓名：{{ user_name }}</div>
								<div>手机号：{{ user_phone }}</div>
							</div>
						</el-form-item>
						<el-form-item label="违章类型" prop="celog_type">
							<el-select filterable v-model="form.celog_type" placeholder="请选择">
								<el-option v-for="(item,index) in page_info.types"
										   :label="item"
										   :key="index"
										   :value="index">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="罚款金额" prop="celog_price">
							<el-input-number v-model="form.celog_price" :min="0.01" :step="0.01" :precision="2"></el-input-number>
							元
						</el-form-item>
						<el-form-item label="扣分" prop="celog_fun">
							<el-input-number v-model="form.celog_fun" :min="0" :step="1"></el-input-number>
						</el-form-item>
						<el-form-item label="描述" prop="celog_desc">
							<el-input type="textarea" v-model="form.celog_desc" class="x-input-60" placeholder="描述"></el-input>
						</el-form-item>
						<el-form-item label="备注" prop="celog_remak">
							<el-input v-model="form.celog_remak" class="x-input-60" placeholder="备注"></el-input>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
					<el-tab-pane v-if="false" label="高级配置" name="2">
						<el-form-item label="用车限制" prop="cspu_only_plan">
							<el-radio-group v-model="form.cspu_only_plan">
								<el-radio :label="0">分时or套餐</el-radio>
								<el-radio :label="1">仅套餐</el-radio>
							</el-radio-group>
							<div class="x-alert">
								<span>仅套餐：只能购买套餐租车，不可使用分时租车</span><br/>
							</div>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
				</el-tabs>
			</el-form>
			<!---->
			<!---->
			<!-- 按钮部分 -->
			<div class="save_wrap">
				<el-button @click="g_page.funcBack" size="mini">返回</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
				<el-checkbox v-if="page_info.is_admin_edit" style="margin-left: 10px;" label="保存后停留" v-model="checked"/>
			</div>
			<!---->
			<!---->
			<!---->
		</el-main>
	</el-container>
</template>

<script>
	export default {
		data() {
			let page_data = {}
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			page_data.user_name = ''
			page_data.user_phone = ''
			//
			return page_data
		},
		mounted() {
			console.log('mounted')
			console.log(this.$route.query)

			this.g_page.funcSetVue(this)
			//
			this.g_page.funcSetApiUrlEdit('/xadmin/app_car/app_car__ensure__edit')
			this.g_page.funcSetApiUrlSave('/xadmin/app_car/app_car__ensure__edit/save')
			let page = this
			//验证
			this.form_rules = {
				__test: [{
					required: true,
					message: '请输入原密码',
					trigger: 'blur'
				}]
			}

			let data = this.$route.query
			this.g_page.funcEdit(data)
		},
		methods: {
			////////////////////////////////
			funcSearchOrder() {
				if (!this.form.sku_id || this.form.sku_id == '') {
					this.g_cc.func_alert('请选择车牌号', 'error')
					return
				}
				if (!this.form.celog_date || this.form.celog_date == '') {
					this.g_cc.func_alert('请选择违章时间', 'error')
					return
				}
				//
				this.form.celog_order_id = ''
				this.user_name = ''
				this.user_phone = ''
				//
				this.g_cc.func_axios({
					url: '/xadmin/app_car/app_car__ensure__edit/funcSearchOrder',
					data: {
						'sku_id': this.form.sku_id,
						'date': this.form.celog_date
					},
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.form.celog_order_id = res.data.entity_order.corder_id
							this.user_name = res.data.entity_user.cuser_name
							this.user_phone = res.data.entity_user.cuser_phone
						} else {
							this.g_cc.func_alert(res.data.errmsg, 'error')
						}
					}
					//
				})
			},
			////////////////////////////////
			funcShowDialogAfter() {
				console.log('funcShowDialogAfter')
			},
			//保存之前
			funcSaveBefore(data) {
				console.log('funcSaveBefore', data)

				// data.abc_str_00 = this.g_page.funcImgArrToStr(data.abc_str_00_imgs)

				return data
			}
		}
	}
</script>
